const app = getApp();
Page({

  data: {
    is_info:0,
    is_school:0,
    is_work:0,
    is_knowledge:0,
    is_other:0,
    school_list:[],
    work_list:[],
    knowledge_list:[],
    click_button:0
  },

  onLoad: function () {
    
  },

  onShow: function () {
    var that = this;
    that.getInformation();
  },

  //获取资料列表
  getInformation: function () {
    var that = this;
    wx.request({
      url: app.globalData.domain + 'index/getInformation/',
      method: "POST",
      data: {
        id: wx.getStorageSync('userinfo').id
      },
      header: {
        "Content-Type" : "application/x-www-form-urlencoded"
      },
      success: function (res) {
        that.setData({
          is_info:res.data.data.is_info,
          is_school:res.data.data.is_school,
          is_work:res.data.data.is_work,
          is_knowledge:res.data.data.is_knowledge,
          is_other:res.data.data.is_other,
          school_list:res.data.data.school_list,
          work_list:res.data.data.work_list,
          knowledge_list:res.data.data.knowledge_list
        })
      }
    })
  },

  editInfo:function(e){
    wx.navigateTo({
      url: '/pages/center/info/edit/info'
    })
  },

  editProve:function(e){
    wx.navigateTo({
      url: '/pages/center/info/edit/prove'
    })
  },

  editSchool:function(e){
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/center/info/edit/school?id=' + id,
    })
  },

  addSchool:function(e){
    wx.navigateTo({
      url: '/pages/center/info/add/school',
    })
  },

  delSchool:function(e){
    var that = this;
    var id = e.currentTarget.dataset.id;
    wx.showModal({
      title: '',
      content: '确定要删除吗？',
      success(res) {
        if (res.confirm) {
          wx.request({
            url: app.globalData.domain + 'index/delSchool/',
            method: "POST",
            data: {
              id: id
            },
            header: {
              "Content-Type" : "application/x-www-form-urlencoded"
            },
            success: function (res) {
              wx.showToast({
                title: res.data.message,
                icon: 'none',
                duration: 2000
              })
              that.getInformation();
            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    }) 
  },

  editWork:function(e){
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/center/info/edit/work?id=' + id,
    })
  },

  addWork:function(e){
    wx.navigateTo({
      url: '/pages/center/info/add/work',
    })
  },

  delWork:function(e){
    var that = this;
    var id = e.currentTarget.dataset.id;
    wx.showModal({
      title: '',
      content: '确定要删除吗？',
      success(res) {
        if (res.confirm) {
          wx.request({
            url: app.globalData.domain + 'index/delWork/',
            method: "POST",
            data: {
              id: id
            },
            header: {
              "Content-Type" : "application/x-www-form-urlencoded"
            },
            success: function (res) {
              wx.showToast({
                title: res.data.message,
                icon: 'none',
                duration: 2000
              })
              that.getInformation();
            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    }) 
  },

  editKnowledge:function(e){
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/center/info/edit/knowledge?id=' + id,
    })
  },

  addKnowledge:function(e){
    wx.navigateTo({
      url: '/pages/center/info/add/knowledge',
    })
  },

  delKnowledge:function(e){
    var that = this;
    var id = e.currentTarget.dataset.id;
    wx.showModal({
      title: '',
      content: '确定要删除吗？',
      success(res) {
        if (res.confirm) {
          wx.request({
            url: app.globalData.domain + 'index/delKnowledge/',
            method: "POST",
            data: {
              id: id
            },
            header: {
              "Content-Type" : "application/x-www-form-urlencoded"
            },
            success: function (res) {
              wx.showToast({
                title: res.data.message,
                icon: 'none',
                duration: 2000
              })
              that.getInformation();
            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    }) 
  }

})